from enum import IntEnum
from typing import Any, Optional

from fastapi.responses import ORJSONResponse


class Response(IntEnum):
    # 成功
    SUCCESS = 0
    # 服务器错误
    SERVER_ERROR = 1
    # 数据库错误
    DATABASE_ERROR = 2

    # 用户已存在
    USER_IS_EXIST = 1001
    # 用户不存在
    USER_IS_NOT_EXIST = 1002
    # 账号或密码不正确
    ACCOUNT_OR_PASSWORD_IS_INCORRECT = 1003


class BaseResponse(ORJSONResponse):

    def __init__(self, msg: str, code: Response | int, data: Optional[Any] = None):
        super().__init__({"msg": msg, "code": code, "data": data})


class SuccessResponse(BaseResponse):
    def __init__(self, msg: str = "ok", code: Response | int = Response.SUCCESS, data: Optional[Any] = None):
        super().__init__(msg, code, data)


class ServerErrorResponse(BaseResponse):
    def __init__(self, msg: str = "server error", code: Response | int = Response.SERVER_ERROR,
                 data: Optional[Any] = None):
        super().__init__(msg, code, data)


class DatabaseErrorResponse(BaseResponse):
    def __init__(self, msg: str = "database error", code: Response | int = Response.DATABASE_ERROR,
                 data: Optional[Any] = None):
        super().__init__(msg, code, data)


class UserIsExistResponse(BaseResponse):
    def __init__(self, msg: str = "user is exits", code: Response | int = Response.USER_IS_EXIST,
                 data: Optional[Any] = None):
        super().__init__(msg, code, data)


class UserIsNotExistResponse(BaseResponse):
    def __init__(self, msg: str = "user is not exits", code: Response | int = Response.USER_IS_NOT_EXIST,
                 data: Optional[Any] = None):
        super().__init__(msg, code, data)


class AccountOrPasswordIsIncorrectResponse(BaseResponse):
    def __init__(self, msg: str = "The account or password is incorrect",
                 code: Response | int = Response.ACCOUNT_OR_PASSWORD_IS_INCORRECT,
                 data: Optional[Any] = None):
        super().__init__(msg, code, data)
